package com.anon.aop;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import com.anon.service.impl.UserService2;

/**
 * @author 徒有琴
 */
public class MyBeanPostProcessor implements BeanPostProcessor {
    //init-method之前
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof UserService2){
            UserService2 obj=(UserService2)bean;
            obj.setStr("b");
        }
        System.out.println("before");
        return bean;
    }
    //init-method之后
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("after");
        return bean;
    }
}
